package game.model;

import java.awt.Color;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Random;

/**
 * @author Jumanah
 * Class Game stores current settings of the game
 */
public class Game {

	public static final int EASY = 1; 
	public static final int MEDIUM = 2;
	public static final int HARD = 3;
	public static final String ENGLISH = "English";
	public static final String SPANISH = "Spanish";
	public static final String FRENCH = "French";
	
	private int boardSize; // the board size variable 
	private int gameMode; // game mode variable	
	private String language; // language variable 	
	private Color background; // background color
	
	// creating class constructor 
	public Game(){
		default_();
	}
			
	// creating class constructor 
	public Game(int boardSize, int gameMode, String language, Color background) {
		
		this.boardSize = boardSize;
		this.gameMode = gameMode;
		this.language = language;
		this.background = background;
		
	}// end constructor 
	
	// set the board size
	public void setBoardSize(int boardSize) {
		this.boardSize = boardSize;
	}
	
	// return the board size
	public int getBoardSize() {
		return boardSize;
	}
	
	// set the game mode
	public void setGameMode(int gameMode) {
		this.gameMode = gameMode;
	}
	
	// return the game mode
	public int getGameMode() {
		return gameMode;
	}

	// set the game language
	public void setLanguage(String language) {
		this.language = language;
	}

	// return the game language
	public String getLanguage() {
		return language;
	}
	
	// set the game background color
		public void setBackground(Color background) {
			this.background = background;
		}

	// return the game background color
	public Color getBackground() {
		return background;
	}

	// This is a method to store the game default settings 
	public void default_(){
		
		gameMode = EASY;
		language = ENGLISH;
		boardSize = 4;
		background = Color.GRAY;
		
	}// end default_
	
	/** Create a board with shuffling blocks.
	 * This method will read images associated with the chosen mode, then
	 * create a board with the chosen size and shuffle blocks */
	public void shuffle(){
		
		Board board = null;
		String path = "";
		
		try {
			path = URLDecoder.decode(Board.class.getResource("../images/").getPath().substring(1), "UTF-8");
		}
		catch (UnsupportedEncodingException e) {
		}
		
		if (gameMode == EASY)
			path += "easy";
		else if (gameMode == MEDIUM)
			path += "medium";
		else
			path += "hard";	
		
		// read images from path
		File dir = new File(path);
		File[] files = dir.listFiles();
			
		// randomly choose images
		Random rand = new Random(System.currentTimeMillis());
		ArrayList<File> tmpList = new ArrayList<File>();
		for (File f : files)
			tmpList.add(f);
		ArrayList<File> fileList = new ArrayList<File>();
		for (int i = 0; i < boardSize*boardSize/2; i++){
			int index = rand.nextInt(tmpList.size());
		fileList.add(tmpList.remove(index));
			}
			
			
			
	}// end shuffle
}// end Game
